package com.sxj.conmon.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author Sun Xiaojie
 */
@Component
public class MySpringContextHolder implements ApplicationContextAware {
	
	static ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		MySpringContextHolder.applicationContext = applicationContext;
	}
	
	public ApplicationContext getApplicationContext () {
		return applicationContext;
	}
	
	public static Object getBean(String beanid) {
	   return applicationContext.getBean(beanid);
	}
	
	public static <T> T getBean(String beanid, Class<T> requiredType) {
		return applicationContext.getBean(beanid, requiredType);
	}
	
}
